<?php

$baseDir = dirname(dirname(dirname(dirname(__FILE__))));
set_include_path(get_include_path().PATH_SEPARATOR.$baseDir.PATH_SEPARATOR.$baseDir.'/incubator');

include '../../testingfunctions.php';
include 'Pone/Pone_Exception.php';
include 'Pone/Database/Pone_Database_ConnectionFactory.php';
include_once './dbconfig.php'; // $config is defined here
include_once './test_setup.php'; // refreshTestData() is defined here

try
{
    refreshTestData($config);
    // /home/web/windows.php.net/docroot/downloads/snaps/
    $conn   = Pone_Database_ConnectionFactory::getConnection($config);
    $pstmt  = $conn->prepareStatement('INSERT INTO test2 (id, username) VALUES (:id, :username)');

    for ($i = 11; $i < 20; $i++)
    {
        $params = array(':id' => $i, ':username' => 'pcdinh'.$i);
        $pstmt->bindParams($params);
        $pstmt->addBatch();
    }

    $updateCount = $pstmt->executeBatch();
    $count       = 0;

    foreach($updateCount as $number => $updateInfo)
    {
        $count  += $updateInfo['affected_rows'];
    }

    assertTrue($count === 9, 'Expected: 9 rows are created. ');

    /*
     for ($i = 11; $i < 20; $i++)
     {
     $params = array(':id' => $i, ':username' => 'pcdinh'.$i);
     $pstmt->bindParams($params);
     $pstmt->addBatch();
     }

     $updateCount = $pstmt->executeBatch();
     */

    // Free resources
    $pstmt->close();
}
catch (Pone_Exception_DatabaseAccess $ex)
{
    echo implode('. ', $ex->getTraceMessages());
    echo '<br />';
    echo $ex->getNativeMessage();
}
catch (Exception $ex)
{
    echo $ex->getMessage();
}

$conn->close();
?>